package com.ant.storage.controller;


import com.ant.storage.common.ResultVo;
import com.ant.storage.dto.DictionaryDto;
import com.ant.storage.pojo.ExcelDataEntity;
import com.ant.storage.service.IDictionaryService;
import com.ant.storage.service.IExcelDataEntityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hzd
 * @since 2025-10-23
 */
@Api(tags = "数据字典接口")
@RestController
@RequestMapping("/dictionary")
public class DictionaryController {

    @Autowired
    IDictionaryService dictionaryService;

    @Autowired
    IExcelDataEntityService entityService;

//    @ApiOperation(value = "获取所有列表")
//    @GetMapping("/list")
//    public ResultVo list(){
//        return ResultVo.success("ok",dictionaryService.list());
//    }

    @ApiOperation(value = "通列表获取对应编号的数据结构列表")
    @GetMapping("/listTree")
    @ApiImplicitParam(name = "type", value = "分类名称 1:7大行业 2:国民经济行业 3:辅料类 4:工业企业生所属行业 5:VOCs 产污系数", required = true,dataType = "String", paramType = "query")
    public ResultVo listTree(String type){
        if (("2").equals(type)) {
            List<ExcelDataEntity> list = entityService.listTree();
            return ResultVo.success("ok",list);
        } else {
            return ResultVo.success("ok",dictionaryService.listTree(type));
        }
    }


    @ApiOperation(value = "添加数据字典")
    @PostMapping("/save")
    public ResultVo save(@RequestBody DictionaryDto dto)
    {
        return ResultVo.success("添加成功",dictionaryService.saveDictionary(dto));
    }

//
//    @PostMapping("/import/dict")
//    public String importDict(@RequestParam String filePath) {
//        String str="D:/environmentProtection/storage/src/main/resources/1.json";
//        try {
//            dictionaryService.importIndustryData(filePath);
//            return "数据导入成功";
//        } catch (Exception e) {
//            e.printStackTrace();
//            return "导入失败：" + e.getMessage();
//        }
//    }
//
//
//    @PostMapping("/import")
//    public String importData() {
//        dictionaryService.importFromJsonFile();
//        return "数据导入完成";
//    }
//
//    @PostMapping("/importFromJson")
//    public String importFromJson(@RequestBody String jsonData) {
//        dictionaryService.importFromJsonString(jsonData);
//        return "数据导入完成";
//    }

//    @GetMapping("/tree")
//    public ResponseEntity<List<IndustryCategory>> getCategoryTree() {
//        List<IndustryCategory> allCategories = repository.findAll();
//
//        return ResponseEntity.ok(allCategories);
//    }
}
